package Controller;

import Dao.ElderInfoDao;
import Dao.QuyuAlarmDao;
import Model.*;
import Model.StatisticalReport.ReportStatisticsQuery;
import Service.ElderInfoService;
import Service.QuyuAlarmService;
import Service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import utils.ReturnDataForLayui;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import utils.permission.ConstantsUtils;

//import com.sun.xml.internal.ws.developer.StreamingAttachment;

@Controller
@RequestMapping("/elderInfo")
public class ElderInfoController {
    private static final Logger logger = LoggerFactory.getLogger(ElderInfoController.class);
    @Autowired
    private ElderInfoService elderInfoService;
    @Autowired
    private UserService userService;
    @Autowired
    ElderInfoDao elderInfoDao;

    @Resource
    QuyuAlarmService quyuAlarmService;
    @Autowired
    QuyuAlarmDao quyuAlarmDao;

    /**
     * 展示全部老人信息
     */
    @RequestMapping("/showElderInfo")
    @ResponseBody
    public PageInfo getElderInfo (@RequestParam(value="pn",defaultValue = "1")Integer pn,@RequestParam(value="limit",defaultValue="10")Integer limit,HttpServletRequest request){
        User user = (User) request.getSession().getAttribute(ConstantsUtils.SessionObj.CURRENT_USER);
        String Role_id=this.userService.findRoleIDbyUserNumber(user.getUser_number());
        if(Role_id.equals("2")){
            //      根据user_number找到结算代码（唯一）
            String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
            System.out.println("找到结算代码："+settleCode);
            //      根据结算代码找到护工
            PageHelper.startPage(pn,limit);
            List<ElderInfo> elderInfos=elderInfoService.getElderbySettleCode(settleCode);
            PageInfo page=new PageInfo(elderInfos);
            return page;
        }else{
            PageHelper.startPage(pn,limit);
            List<ElderInfo> elderInfos=elderInfoService.getAllElderList();
            PageInfo page=new PageInfo(elderInfos);
            return page;
        }
    }
    /**
     * 变更页面：展示全部老人信息
     */
    @RequestMapping("/showElderChangedInfo")
    @ResponseBody
    public PageInfo getElderChangedInfo (HttpServletRequest request,
                                         @RequestParam(value="pn",defaultValue = "1")Integer pn,@RequestParam(value="limit",defaultValue="10")Integer limit){
        User user = (User) request.getSession().getAttribute(ConstantsUtils.SessionObj.CURRENT_USER);
        String Role_id=this.userService.findRoleIDbyUserNumber(user.getUser_number());
        System.out.println("进入老人历史变更页面");
        if(Role_id.equals("2")){
            String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
            System.out.println("找到结算代码："+settleCode);
            PageHelper.startPage(pn,limit);
            List<ElderInfoChanged> elderInfoChangeds=elderInfoService.getAllElderChangedsbySettleCode(settleCode);
            PageInfo page=new PageInfo(elderInfoChangeds);
            return page;
        }else{
            PageHelper.startPage(pn,limit);
            List<ElderInfoChanged> elderInfoChangeds=elderInfoService.getAllElderChangedList();
            PageInfo page=new PageInfo(elderInfoChangeds);
            return page;
        }
    }

    /**
     * 上传老人信息Excel表格
     */
    @RequestMapping(value="/uploadElderInfo",method=RequestMethod.POST)
    @ResponseBody
    public String upload(@RequestParam("file")MultipartFile excl,HttpSession session){
        System.out.println("-----------"+excl);
        elderInfoService.getAllElderList();
        return "成功";
    }

    /**
     * 删除老人
     */
    @RequestMapping(value = "/delElder", method = RequestMethod.POST)
    @ResponseBody
    public String delRole(@RequestParam("id") int id) {
        logger.debug("删除老人--id-" + id);
        try {
            if (id > 0) {
                return elderInfoService.delElder(id);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("删除老人异常！", e);
        }
        return "删除老人出错，请您稍后再试";
    }

    /**
     * 老人信息页面权限:搜索老人
     * @param elderName
     * @param servOrg
     * @param ybID
     * @param personLevel
     * @param personCatagory
     * @param assessType
     * @param serSituation
     * @return
     */
    @RequestMapping("/searchElder")
    @ResponseBody
    public PageInfo findElderInfo(HttpServletRequest request,@RequestParam(value="pn",defaultValue = "1")Integer pn,@RequestParam(value="limit",defaultValue="10")Integer limit,
                                  @RequestParam(value="name")String elderName,@RequestParam(value="serv_org")String servOrg,
                                  @RequestParam(value="ybid")String ybID,@RequestParam(value="person_level")String personLevel,
                                  @RequestParam(value="person_catagory")String personCatagory,@RequestParam(value="assess_type")String assessType,
                                  @RequestParam(value="ser_situation")String serSituation) {
        User user = (User) request.getSession().getAttribute(ConstantsUtils.SessionObj.CURRENT_USER);
        String Role_id=this.userService.findRoleIDbyUserNumber(user.getUser_number());
        if (elderName == "" && servOrg == "" && ybID == "" && personLevel == ""
            && personCatagory == "" && assessType == "" && serSituation == "") {
            System.out.println("controller层：输入框为空");
            if(Role_id.equals("2")){
                String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
                PageHelper.startPage(pn,limit);
                List<ElderInfo> elderInfos=elderInfoService.getElderbySettleCode(settleCode);
                PageInfo page=new PageInfo(elderInfos);
                return page;
            }else{
                PageHelper.startPage(pn,limit);
                List<ElderInfo> elderInfos = elderInfoService.getAllElderList();
                PageInfo page = new PageInfo(elderInfos);
                return page;
            }
        } else {
            System.out.println("controller层：输入框非空");
            if(Role_id.equals("2")){
                String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
                PageHelper.startPage(pn,limit);
                List<ElderInfo> elderInfos = elderInfoService.findElderInfobySettleCode(elderName,servOrg,ybID,personLevel,personCatagory,assessType,serSituation,settleCode);
                PageInfo page = new PageInfo(elderInfos);
                return page;
            }else{
                PageHelper.startPage(pn,limit);
                List<ElderInfo> elderInfos=elderInfoService.findElderInfo(elderName,servOrg,ybID,personLevel,personCatagory,assessType,serSituation);
                PageInfo page = new PageInfo(elderInfos);
                return page;
            }
        }
    }

    /**
     * 搜索/变更页面
     * @param nameSearch
     * @param ybidSearch
     * @param titleSearch
     * @return
     */
    @RequestMapping("/searchChangedInfo")
    @ResponseBody
    public PageInfo searchChangedInfo(HttpServletRequest request,@RequestParam(value="pn",defaultValue = "1")Integer pn,@RequestParam(value="limit",defaultValue="10")Integer limit,@RequestParam(value = "nameSearch") String nameSearch,
                                      @RequestParam(value="ybidSearch")String ybidSearch,
                                      @RequestParam(value="titleSearch")String titleSearch) {
        User user = (User) request.getSession().getAttribute(ConstantsUtils.SessionObj.CURRENT_USER);
        String Role_id=this.userService.findRoleIDbyUserNumber(user.getUser_number());
        if (nameSearch == "" && ybidSearch =="" && titleSearch =="") {
            System.out.println("controller层：搜索框无数据");
            if(Role_id.equals("2")){
                String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
                PageHelper.startPage(pn,limit);
                List<ElderInfoChanged> changedInfo=elderInfoService.getAllElderChangedsbySettleCode(settleCode);
                PageInfo page=new PageInfo(changedInfo);
                return page;
            }else{
                PageHelper.startPage(pn,limit);
                List<ElderInfoChanged> changedInfo = elderInfoService.getAllElderChangedList();
                PageInfo page = new PageInfo(changedInfo);
                return page;
            }
        }
        else{
            System.out.println("contoller层：搜索框非空");
            if(Role_id.equals("2")){
                String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
                List<ElderInfoChanged> changedInfo = elderInfoService.findElderInfoChangedsbySettleCode(nameSearch,ybidSearch,titleSearch,settleCode);
                PageInfo page = new PageInfo(changedInfo);
                return page;
            }else{
                List<ElderInfoChanged> changedInfo = elderInfoService.findElderChangedInfo(nameSearch,ybidSearch,titleSearch);
                PageInfo page = new PageInfo(changedInfo);
                return page;
            }
        }
    }

    /**
     * 创建护工数据
     */
    @RequestMapping(value = "/AddElder")
    @ResponseBody
    public String AddElder(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
        System.out.println("欢迎添加老人");
        int StaUpdate = 0;
        ElderInfo elderInfo=new ElderInfo();
        elderInfo.setName(request.getParameter("name"));

        System.out.println("欢迎添加老人:"+elderInfo.getName());
        elderInfo.setGender(request.getParameter("gender"));
        elderInfo.setAge(request.getParameter("age"));
        elderInfo.setPerson_level(request.getParameter("person_level"));
        elderInfo.setId_number(request.getParameter("id_number"));

        System.out.println("Id_number:"+elderInfo.getId_number());
        elderInfo.setSbcard_id(request.getParameter("sbcard_id"));
        elderInfo.setYbid(request.getParameter("ybid"));
        elderInfo.setJs_id(request.getParameter("js_id"));
        elderInfo.setPerson_catagory(request.getParameter("person_catagory"));

        System.out.println("欢迎添加老人:"+elderInfo.getPerson_catagory());

        elderInfo.setPhone_number(request.getParameter("phone_number"));
        elderInfo.setContact_people(request.getParameter("contact_people"));
        elderInfo.setCare_assistant(request.getParameter("care_assistant"));
        elderInfo.setServ_org(request.getParameter("serv_org"));
        elderInfo.setLast_serv_org(request.getParameter("last_serv_org"));
        elderInfo.setFwaddress(request.getParameter("fwaddress"));
        elderInfo.setFwaddresscj(request.getParameter("fwaddresscj"));
        elderInfo.setFwjz(request.getParameter("fwjz"));

        System.out.println("欢迎添加老人:"+elderInfo.getFwaddress());
//        elderInfo.setDaiyu_start_date(request.getParameter("daiyu_start_date"));
        elderInfo.setSer_situation(request.getParameter("ser_situation"));
        elderInfo.setAssess_type(request.getParameter("assess_type"));

        int update=0;
        int a=0;
        try {
            ElderInfo StfStatus = elderInfoDao.getElderStatus(elderInfo.getYbid());
            System.out.println("查询该老人工状态：");
            if (StfStatus.getSer_situation().equals("无效转出")) {
                System.out.println("更新老人：");
                update = elderInfoDao.updateElderStatus(elderInfo);
                System.out.println("更新老人：");
//                return "{\"msg\":\"ok\"}";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if(update==0){
                a = elderInfoDao.createElderInfo(elderInfo);
                System.out.println("getStatue1" + elderInfo.getName());
            }

//            return "{\"msg\":\"ok\"}";
            //status = 0;
        } catch (Exception e) {
            e.printStackTrace();

        }


//        如果更新了，判断是否异常
        if (a==1||update==1){
            System.out.println("111111111111");
            QuyuAlarm quyuAlarms = new QuyuAlarm();
            if (elderInfo.getServ_org().equals("上海健嘉护理站")) {
                quyuAlarms.setServ_org("上海健嘉护理站");
                System.out.println("elderInfo.getServ_org()"+elderInfo.getServ_org());
                quyuAlarms.setKkfw("安亭镇、外冈镇");
            } else if (elderInfo.getServ_org().equals("上海富兴居家养老服务中心")) {
                quyuAlarms.setServ_org("上海富兴居家养老服务中心");
                quyuAlarms.setKkfw("安亭镇、外冈镇");
            } else if (elderInfo.getServ_org().equals("上海济家外泓护理站")) {
                quyuAlarms.setServ_org("上海济家外泓护理站");
                quyuAlarms.setKkfw("安亭镇、外冈镇");
            } else if (elderInfo.getServ_org().equals("上海外冈镇综合为老服务中心")) {
                quyuAlarms.setServ_org("上海外冈镇综合为老服务中心");
                quyuAlarms.setKkfw("安亭镇、外冈镇");
            } else if (elderInfo.getServ_org().equals("上海夕悦嘉城护理站")) {
                quyuAlarms.setServ_org("上海夕悦嘉城护理站");
                quyuAlarms.setKkfw("马陆镇、南翔镇");
            } else if (elderInfo.getServ_org().equals("上海全程玖玖嘉翔护理站")) {
                quyuAlarms.setServ_org("上海全程玖玖嘉翔护理站");
                quyuAlarms.setKkfw("马陆镇、南翔镇");
            } else if (elderInfo.getServ_org().equals("上海济家虹护理站")) {
                quyuAlarms.setServ_org("上海济家虹护理站");
                quyuAlarms.setKkfw("江桥镇、真新街道");
            } else if (elderInfo.getServ_org().equals("上海嘉康护理站")) {
                quyuAlarms.setServ_org("上海嘉康护理站");
                quyuAlarms.setKkfw("江桥镇、真新街道");
            } else if (elderInfo.getServ_org().equals("上海于勤护理站")) {
                quyuAlarms.setServ_org("上海于勤护理站");
                quyuAlarms.setKkfw("江桥镇、真新街道");
            } else if (elderInfo.getServ_org().equals("上海济家桃溪护理站")) {
                quyuAlarms.setServ_org("上海济家桃溪护理站");
                quyuAlarms.setKkfw("徐行镇、华亭镇、嘉定工业区");
            } else if (elderInfo.getServ_org().equals("上海诺爱居家养老服务中心")) {
                quyuAlarms.setServ_org("上海诺爱居家养老服务中心");
                quyuAlarms.setKkfw("徐行镇、华亭镇、嘉定工业区");
            } else if (elderInfo.getServ_org().equals("上海圣晖护理站")) {
                quyuAlarms.setServ_org("上海圣晖护理站");
                quyuAlarms.setKkfw("徐行镇、华亭镇、嘉定工业区");
            } else if (elderInfo.getServ_org().equals("上海华众护理站")) {
                quyuAlarms.setServ_org("上海华众护理站");
                quyuAlarms.setKkfw("嘉定镇街道、新成路街道、菊园新区");
            } else if (elderInfo.getServ_org().equals("上海嘉恒护理站")) {
                quyuAlarms.setServ_org("上海嘉恒护理站");
                quyuAlarms.setKkfw("嘉定镇街道、新成路街道、菊园新区");
            } else if (elderInfo.getServ_org().equals("上海茁联护理站")) {
                quyuAlarms.setServ_org("上海茁联护理站");
                quyuAlarms.setKkfw("嘉定镇街道、新成路街道、菊园新区");
            } else if (elderInfo.getServ_org().equals("上海海嘉护理站")) {
                quyuAlarms.setServ_org("上海海嘉护理站");
                quyuAlarms.setKkfw("嘉定镇街道、新成路街道、菊园新区");
            }
            quyuAlarms.setName(elderInfo.getName());
            quyuAlarms.setYbid(elderInfo.getYbid());
            quyuAlarms.setFwjz(elderInfo.getFwjz());
            quyuAlarms.setServ_org(elderInfo.getServ_org());
            System.out.println("老人服务街镇："+elderInfo.getYbid());
            System.out.println("老人服务街镇1："+elderInfo.getFwjz());
            System.out.println("老人服务街镇2："+quyuAlarms.getFwjz());
            List<QuyuAlarm> quyuAlarmsRes = new ArrayList<QuyuAlarm>();
            for(int i=0;i<1;i++) {
                if (quyuAlarms.getFwjz().equals("外冈镇")) {
                    if (quyuAlarms.getServ_org().equals("上海健嘉护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海富兴居家养老服务中心")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海济家外泓护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海外冈镇综合为老服务中心")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                } else if (quyuAlarms.getFwjz().equals("安亭镇")) {
                    if (quyuAlarms.getServ_org().equals("上海健嘉护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海富兴居家养老服务中心")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海济家外泓护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海外冈镇综合为老服务中心")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                }
//          东片区
                else if (quyuAlarms.getFwjz().equals("马陆镇")) {
                    if (quyuAlarms.getServ_org().equals("上海夕悦嘉城护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海全程玖玖嘉翔护理站")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                } else if (quyuAlarms.getFwjz().equals("南翔镇")) {
                    if (quyuAlarms.getServ_org().equals("上海夕悦嘉城护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海全程玖玖嘉翔护理站")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                }
//          南片区
                else if (quyuAlarms.getFwjz().equals("江桥镇")) {
                    if (quyuAlarms.getServ_org().equals("上海济家虹护理站")) {
                        System.out.println("quyuAlarms.getFwjz():"+quyuAlarms.getFwjz());
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海于勤护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海嘉康护理站")) {
                        continue;
                    } else {
                        System.out.println("quyuAlarms.getFwjz():"+quyuAlarms.getFwjz());
                        quyuAlarmsRes.add(quyuAlarms);
                        System.out.println("quyuAlarms.getFwjz1():"+ quyuAlarmsRes.size());
                    }
                } else if (quyuAlarms.getFwjz().equals("真新街道")) {
                    System.out.println("000000");
                    if (quyuAlarms.getServ_org().equals("上海济家虹护理站")) {
                        System.out.println("1111111");
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海于勤护理站")) {
                        System.out.println("222222");
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海嘉康护理站")) {
                        System.out.println("33333333");
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                }
//          北片区
                else if (quyuAlarms.getFwjz().equals("徐行镇")) {
                    if (quyuAlarms.getServ_org().equals("上海诺爱居家养老服务中心")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海济家桃溪护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海圣晖护理站")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                } else if (quyuAlarms.getFwjz().equals("华亭镇")) {
                    if (quyuAlarms.getServ_org().equals("上海诺爱居家养老服务中心")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海济家桃溪护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海圣晖护理站")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                } else if (quyuAlarms.getFwjz().equals("嘉定工业区")) {
                    if (quyuAlarms.getServ_org().equals("上海诺爱居家养老服务中心")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海济家桃溪护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海圣晖护理站")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                }
//          中片区
                else if (quyuAlarms.getFwjz().equals("嘉定镇街道")) {
                    if (quyuAlarms.getServ_org().equals("上海华众护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海嘉恒护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海茁联护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海海嘉护理站")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                } else if (quyuAlarms.getFwjz().equals("新成路街道")) {
                    if (quyuAlarms.getServ_org().equals("上海华众护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海嘉恒护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海茁联护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海海嘉护理站")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                } else if (quyuAlarms.getFwjz().equals("菊园新区")) {
                    if (quyuAlarms.getServ_org().equals("上海华众护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海嘉恒护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海茁联护理站")) {
                        continue;
                    } else if (quyuAlarms.getServ_org().equals("上海海嘉护理站")) {
                        continue;
                    } else {
                        quyuAlarmsRes.add(quyuAlarms);
                    }
                }
            }
//            System.out.println("quyuAlarmsRes："+quyuAlarmsRes);

            System.out.println("11111111:"+quyuAlarmsRes.size());
            for (int i = 0;i<quyuAlarmsRes.size();i++){
                System.out.println("新增区域异常数据1");
                int b=quyuAlarmDao.insert(quyuAlarmsRes.get(i));
                System.out.println("新增区域异常数据2");
            }

            return "{\"msg\":\"ok\"}";
        }

        return "{\"msg\":\"error\"}";

    }


    /**
     * 编辑更新老人信息
     */
    @RequestMapping(value = "/updateElder", method = RequestMethod.POST,produces={"application/json;charset=UTF-8"})
    @ResponseBody
    public String updateElder(HttpServletRequest request,ElderInfo elderInfo, HttpSession session) {
        try {
            User user = (User) request.getSession().getAttribute(ConstantsUtils.SessionObj.CURRENT_USER);
            String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
            System.out.println("开始更新");
            String abc=elderInfoService.updateElder(elderInfo, session,settleCode);
            System.out.println("返回结果："+abc);
            if(abc=="ok"){
                return "{\"msg\":\"ok\"}";
            }else{
                return "{\"msg\":\"error\"}";
            }

        } catch (Exception e) {
            e.printStackTrace();
            logger.error("更新异常！", e);
            return "操作异常，请您稍后再试";
        }
    }

    @RequestMapping("/getList")
    @ResponseBody
    public ReturnDataForLayui getList(ElderInfo elderInfo){
        return elderInfoService.getList(elderInfo);
    }

    @RequestMapping("/getList2")
    @ResponseBody
    public ReturnDataForLayui getList2(ElderInfo elderInfo){
        return elderInfoService.getList2(elderInfo);
    }

    /**
     * 上传Excel获取机构数据
     */
    @RequestMapping(value = "/InputExcel")
    @ResponseBody
    public String InputExcel(@RequestParam("file") MultipartFile file, HttpServletRequest request) throws Exception {
        String flag = "02";// 上传标志
        if (!file.isEmpty()) {
            try {
                User user = (User) request.getSession().getAttribute(ConstantsUtils.SessionObj.CURRENT_USER);
                String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
                String originalFilename = file.getOriginalFilename();// 原文件名字
                System.out.println("文件名：" + originalFilename);
                InputStream is = file.getInputStream();// 获取输入流
                flag = elderInfoService.InputExcel(is, originalFilename,settleCode);
                System.out.println("controller层：上传成功，flag= "+flag);
                return "{\"msg\":\"ok\"}";
            } catch (Exception e) {
                flag = "03";// 上传出错
                e.printStackTrace();
                System.out.println("controller层：上传失败，flag= "+flag);
            }
        }
        return "{\"msg\":\"error\"}";
//        return flag;
    }

    /**
     * EXCEL导出-老人信息
     * @param elderName
     * @param servOrg
     * @param ybID
     * @param personLevel
     * @param personCatagory
     * @param assessType
     * @param serSituation
     * @return
     */
    @RequestMapping("/ExportAllInfo")
    @ResponseBody
    public List<ElderInfo> ElderInfo(HttpServletRequest request,@RequestParam(value="name")String elderName,@RequestParam(value="serv_org")String servOrg,
                                     @RequestParam(value="ybid")String ybID,@RequestParam(value="person_level")String personLevel,
                                     @RequestParam(value="person_catagory")String personCatagory,@RequestParam(value="assess_type")String assessType,
                                     @RequestParam(value="ser_situation")String serSituation){
        User user = (User) request.getSession().getAttribute(ConstantsUtils.SessionObj.CURRENT_USER);
        String Role_id=this.userService.findRoleIDbyUserNumber(user.getUser_number());
        if (elderName == "" && servOrg == "" && ybID == "" && personLevel == ""
                && personCatagory == "" && assessType == "" && serSituation == "") {
            System.out.println("controller层：输入框为空");
            if(Role_id.equals("2")){
                String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
                List<ElderInfo> elderInfos=elderInfoService.getElderbySettleCode(settleCode);
                return elderInfos;
            }else{
                List<ElderInfo> elderInfos = elderInfoService.getAllElderList();
                return elderInfos;
            }
        } else {
            System.out.println("controller层：输入框非空");
            if(Role_id.equals("2")){
                String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
                List<ElderInfo> elderInfos = elderInfoService.findElderInfobySettleCode(elderName,servOrg,ybID,personLevel,personCatagory,assessType,serSituation,settleCode);
                return elderInfos;
            }else{
                List<ElderInfo> elderInfos=elderInfoService.findElderInfo(elderName,servOrg,ybID,personLevel,personCatagory,assessType,serSituation);
                return elderInfos;
            }
        }
    }

    /**
     * 导出EXcel/变更页面
     * @param nameSearch
     * @param ybidSearch
     * @param titleSearch
     * @return
     */
    @RequestMapping("/ExportAllChangedInfo")
    @ResponseBody
    public List<ElderInfoChanged> ExportAllChangedInfo(HttpServletRequest request,@RequestParam(value = "nameSearch") String nameSearch,
                                      @RequestParam(value="ybidSearch")String ybidSearch,
                                      @RequestParam(value="titleSearch")String titleSearch) {
        User user = (User) request.getSession().getAttribute(ConstantsUtils.SessionObj.CURRENT_USER);
        String Role_id=this.userService.findRoleIDbyUserNumber(user.getUser_number());
        if (nameSearch == "" && ybidSearch =="" && titleSearch =="") {
            System.out.println("controller层：搜索框无数据");
            if(Role_id.equals("2")){
                String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
                List<ElderInfoChanged> changedInfo=elderInfoService.getAllElderChangedsbySettleCode(settleCode);
                return changedInfo;
            }else{
                List<ElderInfoChanged> changedInfo = elderInfoService.getAllElderChangedList();
                return changedInfo;
            }
        }
        else{
            System.out.println("contoller层：搜索框非空");
            if(Role_id.equals("2")){
                String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
                List<ElderInfoChanged> changedInfo = elderInfoService.findElderInfoChangedsbySettleCode(nameSearch,ybidSearch,titleSearch,settleCode);
                return changedInfo;
            }else{
                List<ElderInfoChanged> changedInfo = elderInfoService.findElderChangedInfo(nameSearch,ybidSearch,titleSearch);
                return changedInfo;
            }
        }
    }

    @RequestMapping("/getLrIdName")
    @ResponseBody
    public List<ElderInfo> getLrIdName(){
        List<ElderInfo> list = elderInfoService.getLrIdName();
        System.out.println("controller层：获取lao老人ID和name成功");
        return list;
    }

    @RequestMapping("/getLrNameByCode")
    @ResponseBody
    public List<ElderInfo> getLrNameByCode(HttpServletRequest request){
        User user = (User) request.getSession().getAttribute(ConstantsUtils.SessionObj.CURRENT_USER);
        String settleCode =userService.findSettleCodebyUserNumber(user.getUser_number());
        System.out.println("找到结算代码："+settleCode);
        List<ElderInfo> list = elderInfoService.getLrNameByCode(settleCode);
        System.out.println("controller层：获取老人姓名成功！");
        return list;
    }

    @RequestMapping("/getLrIdNumberByName")
    @ResponseBody
    public List<ElderInfo> getLrIdNumberByName(HttpServletRequest request){
        String name = request.getParameter("lr_name");
        System.out.println("老人的姓名："+name);
        List<ElderInfo> list = elderInfoService.getLrIdNumberByName(name);
        System.out.println("controller层：获取老人身份证成功！");
        return list;
    }

    @RequestMapping("/findNameByDeviceLr")
    @ResponseBody
    public List<ElderInfo> findNameByDeviceLr(HttpServletRequest request){
        String device_lr = request.getParameter("device_lr");
        List<ElderInfo> list = elderInfoService.findNameByDeviceLr(device_lr);
        System.out.println("controller层：根据设备Id获取老人姓名和医保成功！");
        return list;
    }
}